//
//  ActivityManager.m
//  iModern
//
//  Created by Ralf on 5/13/15.
//  Copyright (c) 2015 com.starlooking. All rights reserved.
//

#import "ActivityManager.h"
#import "AppDelegate.h"

@implementation ActivityManager

- (ResultSet *)queryByFollowing:(NSInteger)max offset:(NSInteger)offset tag:(NSString *)tag
{
    NSDictionary *params      = [NSMutableDictionary new];
    AppDelegate  *appDelegate = [self getAppDelegate];
    if ([appDelegate isLogged])
    {
        [params setValue:[self getSessionID] forKey:@"sessionID"];
    }

    if (tag)
    {
        [params setValue:tag forKey:@"tag"];
    }

    [params setValue:[[NSString alloc] initWithFormat:@"%ld", (long) max] forKey:@"max"];
    [params setValue:[[NSString alloc] initWithFormat:@"%ld", (long) offset] forKey:@"offset"];

    return [self request:@"activity/queryByFollowing" params:params];
}

- (ResultSet *)queryByFavorites:(NSInteger)max offset:(NSInteger)offset tag:(NSString *)tag
{
    NSDictionary *params      = [NSMutableDictionary new];
    AppDelegate  *appDelegate = [self getAppDelegate];
    if ([appDelegate isLogged])
    {
        [params setValue:[self getSessionID] forKey:@"sessionID"];
    }

    if (tag)
    {
        [params setValue:tag forKey:@"tag"];
    }

    [params setValue:[[NSString alloc] initWithFormat:@"%ld", (long) max] forKey:@"max"];
    [params setValue:[[NSString alloc] initWithFormat:@"%ld", (long) offset] forKey:@"offset"];

    return [self request:@"activity/queryByFavorites" params:params];
}

- (ResultSet *)queryByTask:(NSInteger)max offset:(NSInteger)offset tag:(NSString *)tag
{
    NSDictionary *params      = [NSMutableDictionary new];
    AppDelegate  *appDelegate = [self getAppDelegate];
    if ([appDelegate isLogged])
    {
        [params setValue:[self getSessionID] forKey:@"sessionID"];
    }

    if (tag && ![tag isEqualToString:@"(null"])
    {
        [params setValue:tag forKey:@"tag"];
    }

    [params setValue:[[NSString alloc] initWithFormat:@"%ld", (long) max] forKey:@"max"];
    [params setValue:[[NSString alloc] initWithFormat:@"%ld", (long) offset] forKey:@"offset"];

    return [self request:@"activity/queryByTask" params:params];
}

- (ResultSet *)queryByAdvertising:(NSInteger)max offset:(NSInteger)offset tag:(NSString *)tag
{
    NSDictionary *params      = [NSMutableDictionary new];
    AppDelegate  *appDelegate = [self getAppDelegate];
    if ([appDelegate isLogged])
    {
        [params setValue:[self getSessionID] forKey:@"sessionID"];
    }

    if (tag)
    {
        [params setValue:tag forKey:@"tag"];
    }

    [params setValue:[[NSString alloc] initWithFormat:@"%ld", (long) max] forKey:@"max"];
    [params setValue:[[NSString alloc] initWithFormat:@"%ld", (long) offset] forKey:@"offset"];

    return [self request:@"activity/queryByAdvertising" params:params];
}

@end
